#include<iostream>
using namespace std;
#include<iomanip>
#include<ctime>
#include<cmath>
#include<omp.h>

int main(){

	int i, n=1E8;
	double x, pi, sum = 0, h;
	clock_t t_start, t_end;
	
	h = 1.0/n;

	t_start = clock();
	#pragma omp parallel
	{
		double x;
		#pragma omp for reduction(+:sum)
		for(i=0;i<n;i++){
			x = (i+0.5)*h;
			sum = sum + 4.0/(1.0+x*x);
		}
	}
	pi = h * sum;
	t_end = clock();

	cout<<"Elapsed time: "<<(double)(t_end - t_start)/CLOCKS_PER_SEC<<" s.\n";
	cout<<"pi="<<pi<<endl;
	return 0;
}
